import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

void main() {
  runApp(new MaterialApp(
      title: "App",
      theme: new ThemeData.light(),
      home: Material(
        child: Scaffold(
          appBar: AppBar(),
          body: InputScreen(),
        ),
      )));
}

class TextScreenState extends State<TextScreen> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(20),
      child: Column(
        children: <Widget>[
          DefaultTextStyle(
            style: TextStyle(color: Colors.pink),
            child: Column(
              children: <Widget>[
                Text("你是打发大水"),
                Text("你是打发大水"),
                Text(
                  "你是打发大水",
                  style: TextStyle(color: Colors.blue),
                )
              ],
            ),
          ),
          Text.rich(
            TextSpan(
                style:
                    TextStyle(color: Colors.red, backgroundColor: Colors.blue),
                text: "你好",
                children: <TextSpan>[
                  TextSpan(
                      text: "帅哥",
                      style: TextStyle(color: Colors.amber, fontSize: 20))
                ]),
            textAlign: TextAlign.left,
            textDirection: TextDirection.ltr,
          ),
          Text(
            "Hello world" * 2,
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    );
  }
}

class TextScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextScreenState();
  }
}

class ButtonScreenState extends State<ButtonScreen> {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        RaisedButton(
          color: Colors.green,
          textColor: Colors.blue,
          child: Container(
            color: Colors.pink,
            child: Text("按我"),
          ),
          onPressed: () => Fluttertoast.showToast(msg: "啊!被点到了~"),
        ),
        FlatButton(
          onPressed: () => Fluttertoast.showToast(msg: "嗯啊點到我了"),
          child: Text("點我吧"),
          padding: EdgeInsets.all(0),
        ),
        OutlineButton(
          onPressed: () => {},
          child: Text("點吧"),
        ),
        IconButton(
          onPressed: () => {},
          icon: Icon(Icons.access_time),
        )
      ],
    );
  }
}

class ButtonScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ButtonScreenState();
  }
}

class ImageState extends State<ImageScreen> {
  bool _switchState = false;

  @override
  Widget build(BuildContext context) {
    return Row(children: <Widget>[
      Image(
        image: AssetImage("images/ic_test.png"),
      ),
      Image.network(
        "http://g.hiphotos.baidu.com/image/h%3D300/sign=1ae574b8e8cd7b89f66c3c833f254291/1e30e924b899a90182ea2f4413950a7b0308f5e1.jpg",
        color: Colors.blue,
        width: 100,
        colorBlendMode: BlendMode.hardLight,
        fit: BoxFit.fitHeight,
      ),
      Switch(
          value: _switchState,
          onChanged: (bool val) {
            Fluttertoast.showToast(msg: "$val");
            setState(() {
              _switchState = val;
            });
          }),
      Checkbox(
          value: _switchState,
          onChanged: (bool val) {
            setState(() {
              _switchState = val;
            });
          }),
    ]);
  }
}

class ImageScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ImageState();
  }
}

class InputState extends State<InputScreen> {
  TextEditingController _textController = TextEditingController();
  FocusNode focusNode = new FocusNode();
  FocusScopeNode _focusScopeNode ;
  @override
  void initState() {
    super.initState();
    _textController.addListener((){
      print("text changed");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      TextField(
        autofocus: true,
        style: TextStyle(fontSize: 30),
        controller: _textController,
        focusNode: focusNode,
        decoration: InputDecoration(
            labelText: "订单",
            hintText: "SSS",
            errorText: "",
            prefixText: "sdfds",
            suffixText: "fds"),
      ),
      RaisedButton(child: Text("弹出键盘"),onPressed: (){
        if(null == _focusScopeNode){
          _focusScopeNode = FocusScope.of(context);
        }
        _focusScopeNode.requestFocus(focusNode);
        _focusScopeNode.autofocus(focusNode);
      },)
    ]);
  }
}

class InputScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return InputState();
  }
}
